#!/bin/bash

source ./config.sh

cp -f index.html ${OUTPUT_HTML_FILE_DIR}/ > /dev/null

cp -f ${INPUT_FILE_DIR}/*.in ${OUTPUT_HTML_FILE_DIR}/ > /dev/null

for index in $(seq 0 $((${#B_APPS[@]} - 1)))
do

  APP_t=${B_APPS[$index]##*/}

  INPUT_FILE=${APP_t}_${B_ENERGYS[$index]}"GeV_"${B_SAMPLES[$index]}_${B_BFIELDS[$index]}.in

  OUTPUT_HTML_FILE=${APP_t}_${B_ENERGYS[$index]}"GeV_"${B_SAMPLES[$index]}_${B_BFIELDS[$index]}"Tesla_"${B_PYLISTS[$index]}.html

  OUTPUT_PHY_GIF=${APP_t}_${B_ENERGYS[$index]}"GeV_"${B_SAMPLES[$index]}_${B_BFIELDS[$index]}"Tesla_"${B_PYLISTS[$index]}_PHY.gif

  OUTPUT_TIME_GIF=${APP_t}_${B_ENERGYS[$index]}"GeV_"${B_SAMPLES[$index]}_${B_BFIELDS[$index]}"Tesla_"${B_PYLISTS[$index]}_TIME.gif

  OUTPUT_ERR_GIF=${APP_t}_${B_ENERGYS[$index]}"GeV_"${B_SAMPLES[$index]}_${B_BFIELDS[$index]}"Tesla_"${B_PYLISTS[$index]}_ERR.gif

  cp -f ${OUTPUT_PHY_FILE_DIR}/${OUTPUT_PHY_GIF} ${OUTPUT_HTML_FILE_DIR}/ > /dev/null 
  cp -f ${OUTPUT_TIME_FILE_DIR}/${OUTPUT_TIME_GIF} ${OUTPUT_HTML_FILE_DIR}/ > /dev/null 
  cp -f ${OUTPUT_ERR_FILE_DIR}/${OUTPUT_ERR_GIF} ${OUTPUT_HTML_FILE_DIR}/ > /dev/null 

#  echo ${OUTPUT_PHY_FILE_DIR}/${OUTPUT_PHY_GIF} ${OUTPUT_HTML_FILE_DIR}/ 

cat > ${OUTPUT_HTML_FILE_DIR}/${OUTPUT_HTML_FILE} <<EOF
    <html>
    <body>
    <p> * Application     : ${APP_t} </p>
    <p> * Energy          : ${B_ENERGYS[$index]} GeV </p>
    <p> * Particle        : ${B_SAMPLES[$index]}  </p>
    <p> * Magnetic Field  : ${B_BFIELDS[$index]} Tesla </p>
    <p> * Physics List    : ${B_PYLISTS[$index]}  </p>
    <p> * Number of Events: ${B_EVENTS[$index]}  </p>
    <p> * Number of Runs  : ${RUNS} </p>
    <p> * Max # of Threads: ${THREADS[${#THREADS[@]}-1]} </p>
    <p> * <a href="${INPUT_FILE}"> Input File </a>  </p>

    <p> * Average Energy Loss in EM (MeV)</p>
    <p>
      <img src="${OUTPUT_PHY_GIF}" width="50%" height="50%"/>
    </p>

    <p> * Performance (Seconds) </p>
    <p> 
      <img src="${OUTPUT_TIME_GIF}" width="50%" height="50%"/>
    </p>

    <p> * Number of Errors </p>
    <p> 
      <img src="${OUTPUT_ERR_GIF}" width="50%" height="50%"/>
    </p>
    </body>
    </html>
EOF
done

